/*
 * @Author: [wcy]
 * @Date: 2021-12-28 10:44:56
 * @LastEditors: [wcy]
 * @LastEditTime: 2022-01-04 14:41:58
 * @Description: 
 */
//对于axios进行二次封装
import axios from "axios";
import nprogress from "nprogress";
//在当前模块中引入store
import store from '@/store';
// import "nprogress/nprogress.css";
let requests = axios.create({
  //基础路径
  baseURL: "http://127.0.0.1:3007",
  //请求不能超过5S
  timeout: 5000,
});

requests.interceptors.request.use((config) => {
  //可以让进度条开始动
  const token = localStorage.getItem("TOKEN");
  if(token){
    config.headers.Authorization = token;
  }
  nprogress.start();
  return config;
});

//响应拦截器
requests.interceptors.response.use(
  (res) => {
    //进度条结束
    nprogress.done();
    return res.data;
  },
  (err) => {
    // alert("服务器响应数据失败");
  }
);
export default requests;
